var websocket;

function init() {
    output = document.getElementById("output");
}

function send_echo() {
    var wsUri = "ws://127.0.0.1:8090/websocket/1001099";
    writeToScreen("连接 " + wsUri);
    websocket = new WebSocket(wsUri);
    websocket.onopen = function (evt) {
        writeToScreen("连接成功");

    };
    websocket.onmessage = function (evt) {
        writeToScreen("客户端收到来自服务端的消息为: " + evt.data);
    };
    websocket.onerror = function (evt) {
        writeToScreen("<span style='color:red;'>ERROR:</span>" + evt.data);
        websocket.close();
    };
}

function doSend() {
    let message = document.getElementById("message").value;
    websocket.send(message);
    writeToScreen("客户端发送给服务器的数据为: " + message);
}

function writeToScreen(message) {
// console.log("接收到的Message："+message);
    var pre = document.createElement("p");
    pre.style.wordWrap = "bread-word";
    pre.innerHTML = message;
    output.appendChild(pre);
}

function onClose() {
    websocket.close();
}

window.addEventListener("load", init, false);